<?php

namespace app\common\model\auth;

use app\common\model\BaseModel;

class AuthMenuModel extends BaseModel
{
    protected $table = 't_auth_menu';

    const TYPE_MENU = 1;
    const TYPE_BTN = 2;
    public $type = [
        self::TYPE_MENU => '菜单',
        self::TYPE_BTN => '按钮'
    ];

    /**
     * 获取菜单名称路径
     * @param int $menuId
     * @param string $str 分离字符串
     * @param int $depth 递归深度
     * @return string
     */
    public function getMenuNamePath($menuId, $str = '->', $depth = 0)
    {
        $depth++;
        $menuInfo = $this->where('id', $menuId)->find();
        $name = $menuInfo['name'] ?? '';
        if ($menuInfo && !empty($menuInfo['parent_id'])) {
            $temp = $this->getMenuNamePath($menuInfo['parent_id'], $str, $depth);
            if ($temp) {
                $name = "{$temp}{$str}{$name}";
            }
        }

        return $name;
    }

}